package Server.Jsmj.RGCP;

public class RGCPTypeDef {

};

/*
 * // �齫���ͽṹ class BLOCKSTYLE { static int BLOCK_NULL = 0; // �� static int
 * BLOCK_CHI = 1; // ���ƽṹ static int BLOCK_SUN = 2; // ˳��ṹ static int
 * BLOCK_PENG = 3; // ���ӽṹ,3����ͬ static int BLOCK_KE = 4; // ���ӽṹ,3����ͬ,���� static
 * int BLOCK_GANG = 5; // ���ӽṹ,4����ͬ static int BLOCK_AN_GANG = 6; // ���� };
 */
// �齫��ṹ
class BLOCK {
	int style = Constants.BLOCK_NULL; // �齫������
	int first; // �齫���һ����ֵ
	int count;

	@Override
	protected BLOCK clone() {
		BLOCK block = new BLOCK();
		block.style = this.style;
		block.first = this.first;
		block.count = this.count;
		return block;
	}
};

class MJ_BLOCK extends BLOCK {

};

class PTR_MJ_BLOCK extends BLOCK {

};

// ���ƽṹ
class HU {
	int jiangMj = Constants.INVALID_CARD; // ����
	BLOCK block[] = new BLOCK[(Constants.HAND_MJ_MAX - 2) / 3]; // �齫��
	int sanMj[] = new int[Constants.HAND_MJ_MAX]; // ����

	{
		for (int i = 0; i < block.length; i++) {
			block[i] = new BLOCK();
		}
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			sanMj[i] = Constants.INVALID_CARD;
		}
	}

	void removeLastBlock() {
		for (int i = Constants.MAX_BLOCK_NUM - 1; i >= 0; i--) {
			if (block[i].style != Constants.BLOCK_NULL) {
				block[i].style = Constants.BLOCK_NULL;
				block[i].first = 0;
				break;
			}
		}
	}

	public HU clone() {
		HU hu = new HU();
		hu.jiangMj = jiangMj;
		for (int i = 0; i < block.length; i++) {
			hu.block[i] = block[i].clone();
		}
		for (int i = 0; i < Constants.HAND_MJ_MAX; i++) {
			hu.sanMj[i] = sanMj[i];
		}
		return hu;
	}

};

class MJ_HU extends HU {

};

// ����
class GANG {
	int GangMj; // ���ܵ���
	int GangStyle; // ��������,4-����,2-��������,1-��ͨ��,0-�޸�
};

class MJ_GANGINFO extends GANG {
};

class MJ_LONGINFO {
	int GangMj; // ���ܵ���
	int GangStyle; // ��������,5-��,4-����,2-��������,1-��ͨ��,0-�޸�
	int count;
};

// �Բ���
class ACTION_C_Chi {
	int nChiType;// ��������,0-��,1-@@, 2-@@, 3-@@
};

// ������
class ACTION_C_Peng {
	int byOutMj;// �����ƣ��ɲ���
};
// ������������������Բ�������

// �ܲ���
class ACTION_C_Gang {
	int nGangMode;// ��������,0-��, 1-����,2-����, 4-����
	int byGangMj;// ���ܵ��ƣ����������ж��ָ��ƵĿ���
};

class MajSide {
	int Maj[] = new int[Constants.HAND_MJ_MAX];
	int Hua[] = new int[8];
	HU hu = new HU();
	int outMj[] = new int[20];
	int byTing; // �ڼ�������
	int byLastOutMj;
	int DiHu;// ��ҵ׺�

	void Init() {
		CleanHu(hu);
		byTing = 0;
		DiHu = 0;
		Constants.memset(Maj, Constants.INVALID_CARD, Constants.HAND_MJ_MAX);
		Constants.memset(Hua, Constants.INVALID_CARD, 8);
		Constants.memset(outMj, Constants.INVALID_CARD, 20);
		byLastOutMj = Constants.INVALID_CARD;
	}

	MajSide clone(MajSide t) {
		Maj = t.Maj.clone();
		Hua = t.Hua.clone();
		hu = t.hu.clone();
		outMj = t.outMj.clone();
		byTing = t.byTing;
		byLastOutMj = t.byLastOutMj;
		return this;
	}

	// �����������
	void CleanHu(HU hu) {
		hu.jiangMj = (int) Constants.INVALID_CARD;
		for (int i = 0; i < (Constants.HAND_MJ_MAX - 2) / 3; i++) {
			hu.block[i].first = (int) Constants.INVALID_CARD;
			hu.block[i].style = Constants.BLOCK_NULL;
		}
	}

	void SortCard() {
		SortCard((int) (Constants.HAND_MJ_MAX - 1));
	}

	void SortCard(int byHandMjCount) {
		for (int i = 0; i < byHandMjCount - 1; i++) {
			for (int j = i; j < byHandMjCount; j++) {
				int x = Maj[i];
				int y = Maj[j];
				if (x > y) {
					int tempvalue = Maj[i];
					Maj[i] = Maj[j];
					Maj[j] = tempvalue;
				}
			}
		}
	}

	int GetHandMjCount() {
		int byHandMjCount = 0;
		for (int byIndex = 0; byIndex < Constants.HAND_MJ_MAX; byIndex++) {
			if (Maj[byIndex] < 42 && Maj[byIndex] != Constants.INVALID_CARD) {
				byHandMjCount++;
			}
		}
		return byHandMjCount;
	}

	int GetTotalMjCount() {
		int byHandMjCount = 0;
		for (int byIndex = 0; byIndex < Constants.HAND_MJ_MAX; byIndex++) {
			if (Maj[byIndex] < 42 && Maj[byIndex] != Constants.INVALID_CARD) {
				byHandMjCount++;
			}
		}
		for (int byIndex = 0; byIndex < Constants.MAX_BLOCK_NUM; byIndex++) {

			if (hu.block[byIndex].style != Constants.BLOCK_NULL) {
				byHandMjCount = byHandMjCount + 3;
			}

		}
		return byHandMjCount;
	}

	int GetMoPai() {
		return Maj[Constants.HAND_MJ_MAX - 1];
	}

	void SetMoPai(int byMoPai) {
		Maj[Constants.HAND_MJ_MAX - 1] = (int) byMoPai;
	}

	// �������һ�ų���
	void ChuPai(int byChuPai) {
		for (int byIndex = 0; byIndex < 20; byIndex++) {
			if (outMj[byIndex] == Constants.INVALID_CARD) {
				outMj[byIndex] = byChuPai;
				break;
			}
		}
		byLastOutMj = byChuPai;
	}

	int GetChuPaiCount() {
		for (int byIndex = 0; byIndex < 20; byIndex++) {
			if (outMj[byIndex] == Constants.INVALID_CARD) {
				return byIndex;
			}
		}

		return 20;
	}

	// �Ʊ����˳Ե�������������
	void BeiChiPai() {
		for (int byIndex = 19; byIndex >= 0; byIndex--) {
			if (outMj[byIndex] != Constants.INVALID_CARD) {
				outMj[byIndex] = (int) Constants.INVALID_CARD;
				break;
			}
		}
	}

	int GetHandMajCount(int byMajValue) {
		int byHandMjCount = 0;
		for (int byIndex = 0; byIndex < Constants.HAND_MJ_MAX - 1; byIndex++) {
			if (Maj[byIndex] == byMajValue) {
				byHandMjCount++;
			}
		}
		return byHandMjCount;
	}

	void AddHua(int byHua) {
		int byHuaCount = 0;
		for (int byIndex = 0; byIndex < 8; byIndex++) {
			if (Hua[byIndex] >= 34 && Hua[byIndex] < 42) {
				byHuaCount++;
			}
		}
		Hua[byHuaCount] = byHua;
	}

	void JiaoHuan(MajSide t) {
		JiaoHuan(t, false);
	}

	void JiaoHuan(MajSide t, boolean bLastMj) {
		int byMj = Maj[Constants.HAND_MJ_MAX - 1];
		int byMjt = t.Maj[Constants.HAND_MJ_MAX - 1];
		MajSide temp = this;
		// this = t;
		t = temp;
		if (!bLastMj) {
			t.Maj[Constants.HAND_MJ_MAX - 1] = byMjt;
			Maj[Constants.HAND_MJ_MAX - 1] = byMj;
		}
	}
};
